package org.cskj.demo.demo.controller;

import org.cskj.demo.pojo.Shop;
import org.cskj.demo.service.imp.ShopImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/shop")
public class ShopController {
    private final int size=8;
    @Autowired
    private ShopImp shopImp;
    @RequestMapping("/get")
    private List<Shop> getall(int page){
        int count =shopImp.count();
        double pageMax=Math.ceil(count/size);
        System.out.println(count);
        System.out.println(pageMax);
        //计算page是否有效
        page=page>(int)(pageMax)?(int)(pageMax):page;
        //获取数据
        List<Shop> shops=shopImp.seletcLimit(page, (int)size);
        return shops;
    }
}
